home *** CD-ROM | disk | FTP | other *** search
/ Shareware Grab Bag / Shareware Grab Bag.iso / 001 / pibt3sp2.arc / PIBHOSTC.PAS < prev   
Pascal/Delphi Source File  |  1985-10-03  |  28KB  |  736 lines

  1.  
  2. (*----------------------------------------------------------------------*)
  3. (*            Second host mode overlay section starts here              *)
  4. (*----------------------------------------------------------------------*)
  5.  
  6. CONST
  7.    Start_Host_Overlay_Two = 1;
  8.  
  9. (*----------------------------------------------------------------------*)
  10. (*            Do_Host --- Controls execution of host mode               *)
  11. (*----------------------------------------------------------------------*)
  12.  
  13. OVERLAY PROCEDURE Do_Host;
  14.  
  15. (*----------------------------------------------------------------------*)
  16. (*                                                                      *)
  17. (*     Procedure:  Do_Host                                              *)
  18. (*                                                                      *)
  19. (*     Purpose:    Controls host mode                                   *)
  20. (*                                                                      *)
  21. (*     Calling Sequence:                                                *)
  22. (*                                                                      *)
  23. (*        Do_Host;                                                      *)
  24. (*                                                                      *)
  25. (*      Calls:   Async_Send                                             *)
  26. (*               Async_Receive                                          *)
  27. (*               KeyPressed                                             *)
  28. (*               Process_Command                                        *)
  29. (*               ClrScr                                                 *)
  30. (*                                                                      *)
  31. (*----------------------------------------------------------------------*)
  32.  
  33. VAR
  34.    Done   : BOOLEAN                (* TRUE to exit host mode            *);
  35.    Found  : BOOLEAN                (* TRUE if user name found           *);
  36.    Ch     : CHAR                   (* Character read/written            *);
  37.    S_Ch   : CHAR                   (* Parity_stripped character         *);
  38.    MyPass : AnyStr                 (* Password                          *);
  39.    Try    : INTEGER                (* Number of login attempts          *);
  40.    Back   : BOOLEAN                (* Back from file transfers          *);
  41.  
  42. BEGIN (* Do_Host *)
  43.                                    (* Clear comm line of garbage *)
  44.    Async_Purge_Buffer;
  45.                                    (* Expert mode OFF by default *)
  46.    Expert_On  := FALSE;
  47.                                    (* Assume line feeds not needed *)
  48.    CR_LF_Host := CHR( CR );
  49.                                    (* Welcome and linefeed check *)
  50.    Done       := FALSE;
  51.  
  52.    Host_Send_String_With_CR('PibTerm V3.0, October, 1985');
  53.    Host_Send_String_With_CR('Beginning Remote Communications');
  54.    Host_Send_String_With_CR(' ');
  55.    Host_Send_String_With_CR('Test if line feeds required ...');
  56.  
  57.    REPEAT
  58.  
  59.       Async_Purge_Buffer;
  60.  
  61.       Host_Send_String_With_CR(' ');
  62.       Host_Send_String_And_Echo('Are these lines O V E R P R I N T I N G ?');
  63.  
  64.       REPEAT
  65.       UNTIL Async_Receive( Ch ) OR KeyPressed OR ( NOT Host_Carrier_Detect );
  66.  
  67.       S_Ch := CHR( ORD( Ch ) AND $7F );
  68.  
  69.                                    (* Alter parity if required *)
  70.       IF ( S_Ch <> Ch ) THEN
  71.          BEGIN
  72.  
  73.             IF Parity = 'N' THEN
  74.                BEGIN
  75.                   Parity    := 'E';
  76.                   Data_Bits := 7;
  77.                END
  78.             ELSE
  79.                BEGIN
  80.                   Parity    := 'N';
  81.                   Data_Bits := 8;
  82.                END;
  83.  
  84.             Async_Reset_Port( Comm_Port, Baud_Rate, Parity,
  85.                               Data_Bits, Stop_Bits );
  86.  
  87.             WRITELN;
  88.             WRITELN('Communication re-adjusted to parity = ',Parity,
  89.                     ' and data bits = ',Data_Bits);
  90.             WRITELN;
  91.  
  92.          END;
  93.                                    (* Look for keyboard input if any *)
  94.       IF KeyPressed THEN
  95.          BEGIN
  96.             READ( KBD, S_Ch );
  97.             IF ( S_Ch = CHR( ESC ) ) THEN
  98.                Done := TRUE;
  99.          END;
  100.  
  101.       IF ( NOT Done ) THEN
  102.          BEGIN
  103.  
  104.             S_Ch := UpCase( S_Ch );
  105.  
  106.             Host_Send( S_Ch );
  107.  
  108.             IF Printer_On THEN
  109.                WRITE( Lst , S_Ch );
  110.  
  111.             IF Capture_On THEN
  112.                WRITE( Capture_File , S_Ch );
  113.  
  114.          END;
  115.  
  116.       Done := Done OR ( NOT Host_Carrier_Detect );
  117.  
  118.    UNTIL ( S_Ch IN ['Y','N'] ) OR Done;
  119.  
  120.    IF Done THEN Exit;
  121.  
  122.    IF S_Ch = 'Y' THEN
  123.       CR_LF_Host := CHR( CR ) + CHR( LF )
  124.    ELSE
  125.       CR_LF_Host := CHR( CR );
  126.                                    (* Get user's ID and password *)
  127.    Try := 0;
  128.  
  129.    REPEAT
  130.        Try := Try + 1;
  131.        Get_UserInfo( Found );
  132.    UNTIL( ( Try > Max_Login_Try ) OR Found );
  133.  
  134.                                    (* Check for bad logon or carrier drop *)
  135.  
  136.    Done := Done OR ( NOT Found ) OR ( NOT Host_Carrier_Detect );
  137.  
  138.                                    (* Continue to main menu if OK *)
  139.    IF ( NOT Done ) THEN
  140.       BEGIN
  141.                                    (* Mark this as first entry here  *)
  142.          Host_Section := 'I';
  143.                                    (* Loop over main menu until done *)
  144.          REPEAT
  145.  
  146.             IF Host_Section <> 'F' THEN
  147.                Process_Host_Commands( Done )
  148.             ELSE
  149.                REPEAT
  150.                   Process_File_Transfer_Commands( Done, Back );
  151.                UNTIL( Done OR Back );
  152.  
  153.             Done := Done OR ( NOT Host_Carrier_Detect );
  154.  
  155.          UNTIL ( Done );
  156.  
  157.       END;
  158.                                    (* Open log file and record this logout *)
  159.  
  160.    ASSIGN( Log_File, 'PIBTERM.LOG' );
  161.       (*$I-*)
  162.    RESET ( Log_File );
  163.       (*$I+*)
  164.  
  165.    IF Int24Result = 0 THEN
  166.       BEGIN
  167.          CLOSE( Log_File );
  168.          APPEND( Log_File );
  169.       END
  170.    ELSE
  171.       REWRITE( Log_File );
  172.  
  173.    WRITELN( Log_File,'----- Logged off at ',TimeString( TimeOfDay ),' on ',
  174.             DateString );
  175.  
  176.       (*$I-*)
  177.    CLOSE( Log_File );
  178.       (*$I+*)
  179.  
  180. END   (* Do_Host *);
  181.  
  182. (*----------------------------------------------------------------------*)
  183. (*          Initialize_Host_Mode --- Initializes host mode              *)
  184. (*----------------------------------------------------------------------*)
  185.  
  186. OVERLAY PROCEDURE Initialize_Host_Mode;
  187.  
  188. (*----------------------------------------------------------------------*)
  189. (*                                                                      *)
  190. (*     Procedure:  Initialize_Host_Mode                                 *)
  191. (*                                                                      *)
  192. (*     Purpose:    Initializes host mode.                               *)
  193. (*                                                                      *)
  194. (*     Calling Sequence:                                                *)
  195. (*                                                                      *)
  196. (*        Initialize_Host_Mode;                                         *)
  197. (*                                                                      *)
  198. (*     Remarks:                                                         *)
  199. (*                                                                      *)
  200. (*       This routine reads the user file into memory and scans the     *)
  201. (*       message file as well.  The asynchronous communications port    *)
  202. (*       is also initialized.                                           *)
  203. (*                                                                      *)
  204. (*----------------------------------------------------------------------*)
  205.  
  206. VAR
  207.    Qerr     : BOOLEAN;
  208.    User_Line: AnyStr;
  209.    I        : INTEGER;
  210.    Done_Flag: BOOLEAN;
  211.  
  212. (*----------------------------------------------------------------------*)
  213. (*            Get_A_String --- get string up to specified delimeter     *)
  214. (*----------------------------------------------------------------------*)
  215.  
  216. FUNCTION Get_A_String( S : AnyStr; VAR IS: INTEGER; Delim: CHAR ) : AnyStr;
  217.  
  218. (*----------------------------------------------------------------------*)
  219. (*                                                                      *)
  220. (*     Function:   Get_A_String                                         *)
  221. (*                                                                      *)
  222. (*     Purpose:    Gets string up to specified delimeter.               *)
  223. (*                                                                      *)
  224. (*     Calling Sequence:                                                *)
  225. (*                                                                      *)
  226. (*        D_String := Get_A_String( S : AnyStr; VAR IS: INTEGER;        *)
  227. (*                                  Delim: CHAR ) : AnyStr;             *)
  228. (*                                                                      *)
  229. (*           S        --- string to be scanned                          *)
  230. (*           IS       --- first position in S to be scanned             *)
  231. (*           Delim    --- delimeter character to mark end of string     *)
  232. (*                                                                      *)
  233. (*           D_String --- returns substring of S beginning at IS and    *)
  234. (*                        proceeding up to (but not including) Delim,   *)
  235. (*                        or end of string.                             *)
  236. (*                                                                      *)
  237. (*----------------------------------------------------------------------*)
  238.  
  239. VAR
  240.    T: AnyStr;
  241.  
  242. BEGIN (* Get_A_String *)
  243.  
  244.    T := '';
  245.  
  246.    WHILE ( IS <= LENGTH( S ) ) AND ( S[IS] <> Delim ) DO
  247.       BEGIN
  248.          T  := T + S[IS];
  249.          IS := IS + 1;
  250.       END;
  251.  
  252.    Get_A_String := T;
  253.  
  254. END   (* Get_A_String *);
  255.  
  256. (*----------------------------------------------------------------------*)
  257.  
  258. BEGIN (* Initialize_Host_Mode *)
  259.  
  260.    ClrScr;
  261.                                    (* Initialize communications *)
  262.    Async_Init;
  263.  
  264.    Qerr := Async_Open( Comm_Port, Baud_Rate,
  265.                        Parity, Data_Bits, Stop_Bits );
  266.  
  267.                                    (* Set the modem *)
  268.  
  269.    Send_Modem_Command( Modem_Host_Set );
  270.  
  271.    DELAY( One_Second_Delay );
  272.  
  273.    Async_Purge_Buffer;
  274.                                    (* Read in the user file *)
  275.  
  276.    ASSIGN( User_File, Home_Dir + 'PIBTERM.USF' );
  277.       (*$I-*)
  278.    RESET ( User_File );
  279.       (*$I+*)
  280.  
  281.    IF Int24Result <> 0 THEN
  282.       BEGIN
  283.          WRITELN(' ');
  284.          WRITELN('Can''t open user file, host session ended.');
  285.          WRITELN(' ');
  286.          Really_Done := TRUE;
  287.       END
  288.    ELSE
  289.       BEGIN
  290.  
  291.          NUsers := 0;
  292.  
  293.          REPEAT
  294.  
  295.             NUsers := NUsers + 1;
  296.  
  297.             READLN( User_File , User_Line );
  298.  
  299.             WITH User_List[NUsers] DO
  300.                BEGIN
  301.                   I          := 1;
  302.                   First_Name := Trim( UpperCase( Get_A_String( User_Line, I, ';') ) );
  303.                   I          := I + 1;
  304.                   Last_Name  := Trim( UpperCase( Get_A_String( User_Line, I, ';') ) );
  305.                   I          := I + 1;
  306.                   PassWord   := Trim( Get_A_String( User_Line, I, ';') );
  307.                END;
  308.  
  309.          UNTIL ( EOF( User_File ) OR ( NUsers >= MaxUsers ) );
  310.  
  311.            (*$I-*)
  312.          CLOSE( User_File );
  313.            (*$I+*)
  314.  
  315.          WRITELN('There are ',NUsers,' users recorded in user file.');
  316.  
  317.       END;
  318.                                    (* Scan message file to see how *)
  319.                                    (* many messages there are      *)
  320.    NMessages := 0;
  321.  
  322.    ASSIGN( Message_File , Home_Dir + 'PIBTERM.MSG' );
  323.       (*$I-*)
  324.    RESET( Message_File );
  325.       (*$I+*)
  326.  
  327.    IF Int24Result <> 0 THEN
  328.       BEGIN
  329.          WRITELN('No messages in message base.');
  330.       END
  331.    ELSE
  332.       REPEAT
  333.  
  334.          READLN( Message_File , Message_Line );
  335.  
  336.          IF COPY( Message_Line, 1, 6 ) = '== End' THEN
  337.             NMessages := NMessages + 1;
  338.  
  339.       UNTIL ( EOF( Message_File ) );
  340.  
  341.    IF NMessages > 0 THEN
  342.       WRITELN('There are ', NMessages,' messages in message base.');
  343.  
  344.       (*$I-*)
  345.    CLOSE( Message_File );
  346.       (*$I+*)
  347.  
  348. END   (* Initialize_Host_Mode *);
  349.  
  350. (*----------------------------------------------------------------------*)
  351. (*             Terminate_Host_Mode --- Terminate host mode              *)
  352. (*----------------------------------------------------------------------*)
  353.  
  354. OVERLAY PROCEDURE Terminate_Host_Mode;
  355.  
  356. (*----------------------------------------------------------------------*)
  357. (*                                                                      *)
  358. (*     Procedure:  Terminate_Host_Mode                                  *)
  359. (*                                                                      *)
  360. (*     Purpose:    Terminates host mode.                                *)
  361. (*                                                                      *)
  362. (*     Calling Sequence:                                                *)
  363. (*                                                                      *)
  364. (*        Terminate_Host_Mode;                                          *)
  365. (*                                                                      *)
  366. (*     Remarks:                                                         *)
  367. (*                                                                      *)
  368. (*       This routine hangs up the phone.                               *)
  369. (*                                                                      *)
  370. (*----------------------------------------------------------------------*)
  371.  
  372. BEGIN (* Terminate_Host_Mode *)
  373.                                    (* Hang up the phone *)
  374.    IF ( NOT Local_Host ) THEN
  375.       HangUpPhone;
  376.  
  377.    WRITELN;
  378.    WRITELN('Host session ended.');
  379.  
  380. END   (* Terminate_Host_Mode *);
  381.  
  382. (*----------------------------------------------------------------------*)
  383. (*        Wait_For_Ring --- Wait for phone to ring and answer it        *)
  384. (*----------------------------------------------------------------------*)
  385.  
  386. OVERLAY PROCEDURE Wait_For_Ring( VAR Done: BOOLEAN );
  387.  
  388. (*----------------------------------------------------------------------*)
  389. (*                                                                      *)
  390. (*     Procedure:  Wait_For_Ring                                        *)
  391. (*                                                                      *)
  392. (*     Purpose:    Answers the phone in host mode.                      *)
  393. (*                                                                      *)
  394. (*     Calling Sequence:                                                *)
  395. (*                                                                      *)
  396. (*        Wait_For_Ring( VAR Done : BOOLEAN );                          *)
  397. (*                                                                      *)
  398. (*           Done -- set TRUE if carrier drops or Sysop requests        *)
  399. (*                   host mode termination.                             *)
  400. (*                                                                      *)
  401. (*     Remarks:                                                         *)
  402. (*                                                                      *)
  403. (*       This routine answers the phone and analyzes the modem response *)
  404. (*       in order to set the proper baud rate for communications.       *)
  405. (*                                                                      *)
  406. (*----------------------------------------------------------------------*)
  407.  
  408. VAR
  409.    Qerr:      BOOLEAN;
  410.    Modem_Ans: AnyStr;
  411.    Ch:        CHAR;
  412.    I:         INTEGER;
  413.    J:         INTEGER;
  414.    MTimeOut:  BOOLEAN;
  415.    Int_Ch:    INTEGER;
  416.  
  417. (*----------------------------------------------------------------------*)
  418. (*         Host_Baud_Detect --- Detect caller's baud rate from CRs      *)
  419. (*----------------------------------------------------------------------*)
  420.  
  421. PROCEDURE Host_Baud_Detect;
  422.  
  423. (*----------------------------------------------------------------------*)
  424. (*                                                                      *)
  425. (*     Procedure:  Host_Baud_Detect                                     *)
  426. (*                                                                      *)
  427. (*     Purpose:    Detects caller's baud rate from CR entries           *)
  428. (*                                                                      *)
  429. (*     Calling Sequence:                                                *)
  430. (*                                                                      *)
  431. (*        Host_Baud_Detect;                                             *)
  432. (*                                                                      *)
  433. (*     Calls:                                                           *)
  434. (*                                                                      *)
  435. (*        Async_Receive_With_TimeOut                                    *)
  436. (*                                                                      *)
  437. (*     Remarks:                                                         *)
  438. (*                                                                      *)
  439. (*        The initial baud rate is set to 300 baud.  Then, as the       *)
  440. (*        enters characters, we look at each and alter the baud rate    *)
  441. (*        until something recognizable emerges.                         *)
  442. (*                                                                      *)
  443. (*----------------------------------------------------------------------*)
  444.  
  445. CONST
  446.    Wait_Ch_Time = 1                (* Seconds to wait for a character *);
  447.  
  448.                                    (* Supported host mode baud rates *)
  449.    N_Of_Host_Baud_Rates = 3;
  450.  
  451.    Host_Baud_Rates : ARRAY[1..N_Of_Host_Baud_Rates] OF INTEGER
  452.                      = ( 2400, 1200, 300 );
  453.  
  454. VAR
  455.    Found_Speed : BOOLEAN;
  456.    IBaud       : INTEGER;
  457.  
  458. (*----------------------------------------------------------------------*)
  459. (*               Try_Baud_Rate --- Try a specified baud rate            *)
  460. (*----------------------------------------------------------------------*)
  461.  
  462. FUNCTION Try_Baud_Rate( Test_Baud_Rate: INTEGER ) : BOOLEAN;
  463.  
  464. VAR
  465.    Stripped_Ch : INTEGER;
  466.    Timed_Out   : BOOLEAN;
  467.    Ch          : INTEGER;
  468.  
  469. BEGIN (* Try_Baud_Rate *)
  470.                                    (* Assume this baud rate fails *)
  471.    Try_Baud_Rate := FALSE;
  472.                                    (* Set port to given baud rate *)
  473.    Baud_Rate     := Test_Baud_Rate;
  474.  
  475.    Async_Reset_Port( Comm_Port, Baud_Rate, Parity, Data_Bits, Stop_Bits );
  476.  
  477.                                    (* Wait for a character              *)
  478.  
  479.    Async_Receive_With_TimeOut( Wait_Ch_Time , Ch );
  480.    Timed_Out := ( Ch = TimeOut );
  481.    Async_Clear_Errors;
  482.                                    (* Strip parity bit                 *)
  483.    Stripped_Ch := ( Ch AND $7F );
  484.                                    (* See if it's recognizable as CR   *)
  485.                                    (* or space.  If so, then check     *)
  486.                                    (* the parity.                      *)
  487.    IF ( NOT Timed_Out ) THEN
  488.       IF ( Stripped_Ch = CR     )   OR
  489.          ( Stripped_Ch = ORD(' ') ) THEN
  490.          BEGIN
  491.             Try_Baud_Rate := TRUE;
  492.             IF ( Stripped_Ch <> Ch ) THEN
  493.                BEGIN
  494.                   IF Parity = 'N' THEN
  495.                      BEGIN
  496.                         Parity    := 'E';
  497.                         Data_Bits := 7;
  498.                      END
  499.                   ELSE
  500.                      BEGIN
  501.                         Parity    := 'N';
  502.                         Data_Bits := 8;
  503.                      END;
  504.                   Async_Reset_Port( Comm_Port, Baud_Rate, Parity,
  505.                                     Data_Bits, Stop_Bits );
  506.                END;
  507.          END;
  508.  
  509. END   (* Try_Baud_Rate *);
  510.  
  511. (*----------------------------------------------------------------------*)
  512.  
  513. BEGIN (* Host_Baud_Detect *)
  514.                                    (* Indicates if speed detected       *)
  515.    Found_Speed := FALSE;
  516.                                    (* Wait for modem messages to appear *)
  517.  
  518.    DELAY( 2 * Tenth_Of_A_Second_Delay );
  519.  
  520.                                    (* Purge the receive buffer          *)
  521.    Async_Purge_Buffer;
  522.                                    (* Loop until speed found            *)
  523.  
  524.    WHILE ( NOT Found_Speed ) AND ( Async_Carrier_Detect ) DO
  525.       BEGIN
  526.  
  527.          IBaud := 0;
  528.                                    (* Try each baud rate in turn        *)
  529.          REPEAT
  530.  
  531.             IBaud       := IBaud + 1;
  532.             Parity      := 'N';
  533.             Data_Bits   := 8;
  534.             Found_Speed := Try_Baud_Rate( Host_Baud_Rates[IBaud] );
  535.  
  536.          UNTIL ( Found_Speed ) OR ( IBaud >= N_Of_Host_Baud_Rates );
  537.  
  538.                                    (* If we found the speed, try   *)
  539.                                    (* getting a second character.  *)
  540.                                    (* If it's not recognizable,    *)
  541.                                    (* then it didn't work.         *)
  542.          IF Found_Speed THEN
  543.             Found_Speed := Try_Baud_Rate( Host_Baud_Rates[IBaud] );
  544.  
  545.                                    (* If we didn't get the speed,  *)
  546.                                    (* flush the buffer before next *)
  547.                                    (* try.                         *)
  548.  
  549.          IF ( NOT Found_Speed ) THEN
  550.             BEGIN
  551.                DELAY( 5 );
  552.                Async_Purge_Buffer;
  553.             END;
  554.  
  555.       END  (* WHILE *);
  556.                                    (* Flush the buffer once more *)
  557.    DELAY( Tenth_Of_A_Second_Delay );
  558.  
  559.    Async_Purge_Buffer;
  560.  
  561.    WRITELN('Communications adjusted to ',Baud_Rate,' baud and parity = ',
  562.            Parity );
  563.  
  564. END    (* Host_Baud_Detect *);
  565.  
  566. (*----------------------------------------------------------------------*)
  567. (*     Host_AutoBaud_Detect --- Detect caller's baud rate from modem    *)
  568. (*----------------------------------------------------------------------*)
  569.  
  570. PROCEDURE Host_AutoBaud_Detect;
  571.  
  572. VAR
  573.    New_Baud:  INTEGER;
  574.  
  575. BEGIN (* Host_AutoBaud_Detect *)
  576.  
  577.    New_Baud := 0;
  578.    J        := POS( Modem_Connect, Modem_Ans ) + LENGTH( Modem_Connect );
  579.  
  580.    FOR I := J TO LENGTH( Modem_Ans ) DO
  581.       IF Modem_Ans[I] IN ['0'..'9'] THEN
  582.          New_Baud := New_Baud * 10 + ORD( Modem_Ans[I] ) - ORD('0');
  583.  
  584.    IF New_Baud = 0 THEN New_Baud := 300;
  585.  
  586.    IF New_Baud > 0 THEN
  587.       BEGIN
  588.  
  589.          Baud_Rate := New_Baud;
  590.  
  591.          Async_Reset_Port( Comm_Port, Baud_Rate, Parity, Data_Bits, Stop_Bits );
  592.  
  593.          WRITELN('Communications adjusted to ',Baud_Rate,' baud.');
  594.  
  595.       END;
  596.  
  597. END   (* Host_AutoBaud_Detect *);
  598.  
  599. (*----------------------------------------------------------------------*)
  600.  
  601. BEGIN (* Wait_For_Ring *)
  602.                                    (* Nothing from modem yet *)
  603.    Modem_Ans  := '';
  604.                                    (* Assume remote session  *)
  605.    Local_Host := FALSE;
  606.                                    (* Raise terminal ready   *)
  607.    Async_Term_Ready( TRUE );
  608.                                    (* Not done yet           *)
  609.    Done := FALSE;
  610.                                    (* Display intro blurb    *)
  611.  
  612.    WRITELN('Waiting for phone to ring.');
  613.    WRITELN('Hit ESC key to return to terminal mode.');
  614.    WRITELN('F1 starts/stops chat mode.');
  615.    WRITELN('F2 immediately logs out remote user.');
  616.    WRITELN('Hit any other key to start local host session.');
  617.  
  618.                                    (* Remove any pending input     *)
  619.    Async_Purge_Buffer;
  620.  
  621.    REPEAT                          (* Wait for ring/carrier detect *)
  622.  
  623.       IF KeyPressed THEN
  624.          BEGIN
  625.             READ( Kbd, Ch );
  626.             IF Ch = CHR( ESC ) THEN
  627.                BEGIN
  628.                   IF KeyPressed THEN
  629.                      Local_Host := TRUE
  630.                   ELSE
  631.                      Done := TRUE;
  632.                END
  633.             ELSE
  634.                Local_Host := TRUE;
  635.          END;
  636.  
  637.    UNTIL ( Host_Carrier_Detect ) OR Done OR Local_Host;
  638.  
  639.    IF Done THEN Really_Done := TRUE;
  640.  
  641.                                    (* If local host session,   *)
  642.                                    (* turn off terminal ready  *)
  643.                                    (* so phone isn't answered. *)
  644.    IF Local_Host THEN
  645.       BEGIN
  646.          WRITELN('Local host session begins ... ');
  647.          Async_Term_Ready( FALSE );
  648.          EXIT;
  649.       END;
  650.  
  651.    IF NOT Done THEN
  652.       BEGIN                        (* Answer the phone *)
  653.  
  654.          WRITELN('Answered phone ... ');
  655. (*---------------------------------------------------------------*)
  656. (*                                                               *)
  657. (*       ----- Let the modem answer the phone -----              *)
  658. (*                                                               *)
  659. (*       Send_Modem_Command( Modem_Answer );                     *)
  660. (*                                                               *)
  661. (*---------------------------------------------------------------*)
  662.  
  663.          DELAY( One_Second_Delay );
  664.  
  665.                                    (* Collect modem response for *)
  666.                                    (* later analysis.            *)
  667.          MTimeOut := FALSE;
  668.  
  669.          REPEAT
  670.  
  671.             Async_Receive_With_TimeOut( 1 , Int_Ch );
  672.  
  673.             IF Int_Ch <> TimeOut THEN
  674.                BEGIN
  675.                   Ch := CHR( Int_Ch );
  676.                   IF Ch IN ['A'..'Z',' ','0'..'9'] THEN
  677.                      Modem_Ans := Modem_Ans + Ch;
  678.                   WRITE( Ch );
  679.                   IF Printer_On THEN
  680.                      WRITE( Lst , Ch );
  681.                   IF Capture_On THEN
  682.                      WRITE( Capture_File , Ch );
  683.                END
  684.             ELSE
  685.                MTimeOut := TRUE;
  686.  
  687.          UNTIL ( MTimeOut OR Done );
  688.  
  689.                                    (* Find speed for caller's modem. *)
  690.          IF ( NOT Done ) THEN
  691.             IF Host_Auto_Baud THEN
  692.                Host_AutoBaud_Detect
  693.             ELSE
  694.                Host_Baud_Detect;
  695.  
  696.       END  (* NOT Done *);
  697.  
  698.    Done := Done OR ( NOT Host_Carrier_Detect );
  699.  
  700. END   (* Wait_For_Ring *);
  701.  
  702. (*----------------------------------------------------------------------*)
  703. (*            Emulate_Host_Mode --- main routine for host mode          *)
  704. (*----------------------------------------------------------------------*)
  705.  
  706. BEGIN (* Emulate_Host_Mode *)
  707.  
  708.    Host_Mode   := TRUE;
  709.    Done        := FALSE;
  710.    Really_Done := FALSE;
  711.    First_Time  := TRUE;
  712.                                    (* Initialize host mode *)
  713.    Initialize_Host_Mode;
  714.  
  715.    IF ( NOT Really_Done ) THEN
  716.       REPEAT
  717.                                    (* Wait for call *)
  718.          Wait_For_Ring( Done );
  719.                                    (* Do a host session *)
  720.          IF NOT Done THEN Do_Host;
  721.                                    (* End host session *)
  722.          Terminate_Host_Mode;
  723.  
  724.       UNTIL Really_Done;
  725.  
  726.    WRITELN(' ');
  727.    WRITELN('Host mode communications closed down, ');
  728.    WRITELN('returning to terminal emulation mode. ');
  729.  
  730.                                    (* Restore previous terminal type *)
  731.  
  732.    Terminal_To_Emulate := Saved_Gossip_Term;
  733.    Host_Mode           := FALSE;
  734.  
  735. END   (* Emulate_Host_Mode *);
  736.